home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
-
- CBigArray.c
-
- ******************************************************************************/
-
- #include "CBigArray.h"
-
- /*---------------------------------------------------------------------------*/
-
- void CBigArray::IBigArray(void)
- {
- hData = NULL;
- amf.nElements = 0;
- amf.nElementSize = 0;
- }
-
- /*---------------------------------------------------------------------------*/
-
- Boolean CBigArray::CreateData(long nElements,int nElementSizeIn,Handle hDataIn)
- {
- amf.nElements = nElements;
- amf.nElementSize = nElementSizeIn;
-
- if (hDataIn == NULL) {
- gApplication->RequestMemory(FALSE, TRUE);
- hData = NewHandleClear((long) amf.nElementSize * (long) nElements);
- gApplication->RequestMemory(FALSE, TRUE);
- }
- else
- hData = hDataIn;
-
- if (hData == NULL) return FALSE;
-
- return TRUE;
- }
-
- /*---------------------------------------------------------------------------*/
-
- Boolean CBigArray::ResizeArray(long nNewNumberOfElements)
- {
- OSErr nError;
-
- SetHandleSize(hData,nNewNumberOfElements * amf.nElementSize);
- nError = MemError();
- if (nError == NoErr) {
- amf.nElements = nNewNumberOfElements;
- return TRUE;
- } else
- return FALSE;
- }
-
- /*---------------------------------------------------------------------------*/
-
- void CBigArray::Dispose(void) /* OVERRIDE */
- {
- if (hData != NULL) DisposHandle(hData);
- inherited::Dispose();
- }
-
- /*---------------------------------------------------------------------------*/
-
- void CBigArray::GetValue(long nIndex,char *pDestination)
- {
- register char *pData;
- register int i;
-
- HLock(hData);
- pData= (char *) *hData;
- pData += Offset(nIndex);
-
- for (i=0; i < amf.nElementSize; ++i)
- *pDestination++ = *pData++;
- HUnlock(hData);
- return;
- }
-
- /*---------------------------------------------------------------------------*/
-
- void CBigArray::SetValue(long nIndex,char *pSource)
- {
- register char *pData;
- register int i;
-
- HLock(hData);
-
- pData= (char *) *hData;
- pData += Offset(nIndex);
-
- for (i=0; i < amf.nElementSize; ++i)
- *pData++ = *pSource++;
- HUnlock(hData);
- return;
- }
-
- /*---------------------------------------------------------------------------*/
-
- OSErr CBigArray::SaveData(CDataFile *datafile)
- {
- AMFData amfLocal; /* Used to avoid implicit dereferencing errors */
- OSErr nError;
- long lDataSize;
-
- /*-- Write array mapping data --*/
- amfLocal = amf;
- nError = datafile->WriteSome((char *) &amfLocal,(long) sizeof(AMFData));
- if (nError != NoErr) return nError;
-
- /*-- Write array --*/
- lDataSize = (long) GetHandleSize(hData);
- HLock(hData);
- nError = datafile->WriteSome((char *) *hData, lDataSize);
- HUnlock(hData);
- return nError;
- }
-
- /*---------------------------------------------------------------------------*/
-
- OSErr CBigArray::LoadData(CDataFile *datafile)
- {
- AMFData amfLocal; /* Used to avoid implicit dereferencing errors */
- OSErr nError;
- long nHandleSize;
-
- /*-- Read array mapping data --*/
- nError = datafile->ReadSome((char *) &amfLocal, (long) sizeof(AMFData));
- if (nError != NoErr) return nError;
- amf = amfLocal;
-
- /*-- Allocate Array --*/
- nHandleSize = (long) amf.nElementSize * (long) amf.nElements;
-
- gApplication->RequestMemory(FALSE, TRUE);
- hData = NewHandle(nHandleSize);
- gApplication->RequestMemory(FALSE, FALSE);
- if (hData == NULL) return MemError();
-
- /*-- Read array --*/
- HLock(hData);
- nError = datafile->ReadSome((char *) *hData,nHandleSize);
- HUnlock(hData);
-
- return nError;
- }
-
- /*---------------------------------------------------------------------------*/
-
- void CBigArray::GetDimensions(long *nElements, int *nElementSizeOut)
- {
- *nElements = amf.nElements;
- *nElementSizeOut = amf.nElementSize;
- }
-
- /*---------------------------------------------------------------------------*/
-
- Handle CBigArray::GetData(void)
- {
- return hData;
- }
-
- /*---------------------------------------------------------------------------*/
-
- long CBigArray::Offset(long nIndex)
- {
- return (long) nIndex * (long) amf.nElementSize;
- }
-
- /*---------------------------------------------------------------------------*/
-
-
-